//
//  WXPAlreadyAuthLimitView.m
//  已认证- 最顶部 - 用户额度说明
//
//  Created by wxp on 2025/3/8.
//

#import "WXPAlreadyAuthLimitView.h"

@implementation WXPAlreadyAuthLimitView

#pragma mark - lazy
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewBack;
}
- (UIImageView *)imageLogo{
    if (_imageLogo == nil) {
        _imageLogo = [UIImageView new];
        _imageLogo.image = [UIImage imageNamed:@"icon-limit-logo"];
        _imageLogo.widthHeight = XY(68, 68);
    }
    return _imageLogo;
}
- (UILabel *)labelName{
    if (_labelName == nil) {
        _labelName = [UILabel new];
        _labelName.textColor = COLOR_BLACK;
        _labelName.font = [UIFont boldSystemFontOfSize:16];
    }
    return _labelName;
}
-(UIButton *)btnDetail{
    if (_btnDetail == nil) {
        _btnDetail = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString * buttonText = @"Ver descripción";
        UIImage * arrowImage = [UIImage imageNamed:@"icon-arrow-detail"];
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:buttonText];
        [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, buttonText.length)];
        [attributedString addAttribute:NSForegroundColorAttributeName value:COLOR_LIGHT_GRAY range:NSMakeRange(0, buttonText.length)];
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        attachment.image = arrowImage;
        attachment.bounds = CGRectMake(0, -2, 14, 14);
        NSAttributedString *arrowString = [NSAttributedString attributedStringWithAttachment:attachment];
        [attributedString appendAttributedString:arrowString];
        [_btnDetail setAttributedTitle:attributedString forState:UIControlStateNormal];
        [_btnDetail sizeToFit];
        [_btnDetail setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
            [NSObject clickFeedback];
            [Global_Nav pushVCName:@"WXPAmountExplainVC" animated:true];
        }];
    }
    return _btnDetail;
}
- (UILabel *)labelUnit{
    if (_labelUnit == nil) {
        _labelUnit = [UILabel new];
        _labelUnit.textColor = COLOR_RED;
        _labelUnit.font = [UIFont boldSystemFontOfSize:24];
        [_labelUnit fitTitle:@"$" variable:0];
    }
    return _labelUnit;
}
- (UILabel *)labelMoney{
    if (_labelMoney == nil) {
        _labelMoney = [UILabel new];
        _labelMoney.textColor = COLOR_RED;
        _labelMoney.font = [UIFont boldSystemFontOfSize:35];
    }
    return _labelMoney;
}
- (UIView *)viewContentBack{
    if (_viewContentBack == nil) {
        _viewContentBack = [UIView new];
        _viewContentBack.backgroundColor = COLOR_CARD_BACKGROUND;
        [GlobalMethod setRoundView:_viewContentBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewContentBack;
}
- (UILabel *)labelUtilTitle{
    if (_labelUtilTitle == nil) {
        _labelUtilTitle = [UILabel new];
        _labelUtilTitle.textColor = COLOR_CONTENT;
        _labelUtilTitle.fontNum = 10;
    }
    return _labelUtilTitle;
}
- (UILabel *)labelUtil{
    if (_labelUtil == nil) {
        _labelUtil = [UILabel new];
        _labelUtil.textColor = COLOR_BLACK;
        _labelUtil.font = [UIFont boldSystemFontOfSize:20];
    }
    return _labelUtil;
}
- (UILabel *)labelCongTitle{
    if (_labelCongTitle == nil) {
        _labelCongTitle = [UILabel new];
        _labelCongTitle.textColor = COLOR_CONTENT;
        _labelCongTitle.fontNum = 10;
    }
    return _labelCongTitle;
}
- (UILabel *)labelCong{
    if (_labelCong == nil) {
        _labelCong = [UILabel new];
        _labelCong.textColor = COLOR_BLACK;
        _labelCong.font = [UIFont boldSystemFontOfSize:20];
    }
    return _labelCong;
}
- (UILabel *)labelDispTitle{
    if (_labelDispTitle == nil) {
        _labelDispTitle = [UILabel new];
        _labelDispTitle.textColor = COLOR_CONTENT;
        _labelDispTitle.fontNum = 10;
    }
    return _labelDispTitle;
}
- (UILabel *)labelDisp{
    if (_labelDisp == nil) {
        _labelDisp = [UILabel new];
        _labelDisp.textColor = COLOR_BLACK;
        _labelDisp.font = [UIFont boldSystemFontOfSize:20];
    }
    return _labelDisp;
}
- (UIView *)lineLeft{
    if (_lineLeft == nil) {
        _lineLeft = [UIView new];
        _lineLeft.backgroundColor = COLOR_WHITE;
    }
    return _lineLeft;
}
- (UIView *)lineRight{
    if (_lineRight == nil) {
        _lineRight = [UIView new];
        _lineRight.backgroundColor = COLOR_WHITE;
    }
    return _lineRight;
}

#pragma mark 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, 0);
        self.backgroundColor = [UIColor clearColor];
        [self addSubView];
    }
    return self;
}
//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.imageLogo];
    [self.viewBack addSubview:self.labelName];
    [self.viewBack addSubview:self.btnDetail];
    [self.viewBack addSubview:self.labelUnit];
    [self.viewBack addSubview:self.labelMoney];
    
    [self.viewBack addSubview:self.viewContentBack];
    [self.viewContentBack addSubview:self.labelUtilTitle];
    [self.viewContentBack addSubview:self.labelUtil];
    [self.viewContentBack addSubview:self.labelCongTitle];
    [self.viewContentBack addSubview:self.labelCong];
    [self.viewContentBack addSubview:self.labelDispTitle];
    [self.viewContentBack addSubview:self.labelDisp];
    [self.viewContentBack addSubview:self.lineLeft];
    [self.viewContentBack addSubview:self.lineRight];
    
    [self resetWithModel:[ModelUserCreditInfo new]];
}

#pragma mark 刷新view
- (void)resetWithModel:(ModelUserCreditInfo *)model{
    //刷新view
    self.viewBack.widthHeight = XY(SCREEN_WIDTH-2*LEFT_MARDIN, 0);
    
    self.imageLogo.leftTop = XY(LEFT_MARDIN, LEFT_MARDIN);
    
    [self.labelName fitTitle:@"Cuota total" variable:0];
    self.labelName.leftTop = XY(self.imageLogo.right+12, self.imageLogo.top+3);
    
    self.btnDetail.rightCenterY = XY(self.viewBack.width-self.imageLogo.left, self.labelName.centerY);
    
    self.labelUnit.left = self.labelName.left;
    
    [self.labelMoney fitTitle:[GlobalMethod showMoney:strDot2F(model.total)] variable:0];
    self.labelMoney.leftBottom = XY(self.labelUnit.right+4, self.imageLogo.bottom+2);
    self.labelUnit.bottom = self.labelMoney.bottom-5;
    
    self.viewContentBack.widthHeight = XY(self.viewBack.width-2*self.imageLogo.left, 0);
    self.viewContentBack.centerXTop = XY(self.viewBack.width/2, self.imageLogo.bottom+18);
    
    [self.labelCongTitle fitTitle:@"Cuota congelada" variable:0];
    self.labelCongTitle.centerXTop = XY(self.viewContentBack.width/2, 16);
    [self.labelCong fitTitle:[NSString stringWithFormat:@"$ %@",[GlobalMethod showMoney:strDot2F(model.locking)]] variable:0];
    self.labelCong.centerXTop = XY(self.labelCongTitle.centerX, self.labelCongTitle.bottom+20);
    
    [self.labelUtilTitle fitTitle:@"Cuota utilizada" variable:0];
    self.labelUtilTitle.centerXCenterY = XY(self.viewContentBack.width/6, self.labelCongTitle.centerY);
    [self.labelUtil fitTitle:[NSString stringWithFormat:@"$ %@",[GlobalMethod showMoney:strDot2F(model.used)]] variable:0];
    self.labelUtil.centerXCenterY = XY(self.labelUtilTitle.centerX, self.labelCong.centerY);
    
    [self.labelDispTitle fitTitle:@"Cuota disponible" variable:0];
    self.labelDispTitle.centerXCenterY = XY(self.viewContentBack.width/6*5, self.labelUtilTitle.centerY);
    [self.labelDisp fitTitle:[NSString stringWithFormat:@"$ %@",[GlobalMethod showMoney:strDot2F(model.unused)]] variable:0];
    self.labelDisp.centerXCenterY = XY(self.labelDispTitle.centerX, self.labelUtil.centerY);
    
    self.viewContentBack.height = self.labelDisp.bottom+self.labelDispTitle.top;
    
    self.lineLeft.widthHeight = XY(1, self.viewContentBack.height-17-17);
    self.lineLeft.centerXCenterY = XY(self.viewContentBack.width/3, self.viewContentBack.height/2);
    self.lineRight.widthHeight = self.lineLeft.widthHeight;
    self.lineRight.centerXCenterY = XY(self.viewContentBack.width/3*2, self.viewContentBack.height/2);
    
    self.viewBack.height = self.viewContentBack.bottom+LEFT_MARDIN;
    self.viewBack.centerXTop = XY(self.width/2, 0);
    self.height = self.viewBack.bottom+LEFT_MARDIN;
}

@end
